home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 12796 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.3 KB

  1. Path: apccorp.apcc.com!root
  2. From: nfegan@apcc.com (Noel Fegan)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: How Do I Color A Button?
  5. Date: Thu, 21 Mar 1996 16:18:35 GMT
  6. Organization: American Power Conversion
  7. Message-ID: <4irvip$5m9@apccorp.apcc.com>
  8. References: <4ik07d$7nj@cliffy.lfwc.lockheed.com>
  9. NNTP-Posting-Host: hewie.galway.apcc.com
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. James Bassett <bassett@flash.net> wrote:
  13.  
  14. >Need to know how to color a button in a dialog box. I have tried using 
  15. >SetBkColor, FillRect and CBrush class but with no results. HELP
  16.  
  17. >                    Jim Bassett
  18.  
  19. From the API functions you mention I am assuming you mean MS Windows. By a
  20. button I presume you mean pushbuttons. In Windows the term button is s general
  21. term which covers push buttons, radio buttons and check boxes. I looked into
  22. this before and I found that you cannot alter the color of a pushbutton.
  23.  
  24. If you are using Microsoft MFC framework then note that the framework calls the
  25. function CWnd::OnCtlColor when a child control is about to be drawn.
  26.  
  27. afx_msg HBRUSH OnCtlColor( CDC* pDC, CWnd* pWnd, UINT nCtlColor );
  28.  
  29. Most controls send this message to their parent (usually a dialog box) to
  30. prepare the pDC for drawing the control using the correct colors.
  31.  
  32. To change the text color, call the SetTextColor member function with the desired
  33. red, green, and blue (RGB) values. 
  34.  
  35. To change the background color of a single-line edit control, set the brush
  36. handle in both the CTLCOLOR_EDIT and CTLCOLOR_MSGBOX message codes, and call the
  37. CDC::SetBkColor function in response to the CTLCOLOR_EDIT code.
  38.  
  39. Note, however, that the nCtlColor parameter can be CTLCOLOR_BTN, but even if you
  40. call SetBkColor here for the control it has no effect. The pushbutton always
  41. remains the color it is set in the "Colors" setting in Control Panel.
  42.  
  43. There is a way of changing the color of all buttons, by calling the SetSysColors
  44. function. However, this makes all the buttons in every application this color,
  45. which is probably not what you want.
  46.  
  47. IMHO, the only way to color individual pushbuttons' colors is to draw them as
  48. ownerdraw button and draw them yourself, replicating the way Windows does it,
  49. except choosing the colors yourself.
  50.  
  51.  
  52. --
  53. Noel Fegan
  54. European Software Development Department
  55. American Power Conversion
  56. I don't speak for APC...
  57. nfegan@apcc.com
  58.  
  59.